﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnPlay_Click(object sender, EventArgs e)
        {
            int team1totalScore = GenerateScore();
            label4.Text = team1totalScore.ToString() + " All Out";
            int team2totalScore = GenerateScore();
            label5.Text = team2totalScore.ToString() + " All Out";
            if (team1totalScore < team2totalScore)
                MessageBox.Show("Australia wins");
            else if (team2totalScore < team1totalScore)
                MessageBox.Show("India wins");
            else
                MessageBox.Show("Match ends in a tie");
        }

        private static int GenerateScore()
        {
            Random r = new Random();
            string s = null;
            //byte b = Convert.ToByte("india");

            int iDots = 0;
            int totalScore = 0;
            for (int i = 0; i < 300; i++)
            {
                DateTime dt = DateTime.Now;
                long l = dt.Ticks;
                int iCurrent = r.Next(0, (int)(l % 6) + 1);
                if (iCurrent == 0)
                    iDots++;
                //int iCurrent = r.Next(0, ii);
                totalScore = totalScore + iCurrent;
            }
            MessageBox.Show("Dot balls : " + iDots);
            return totalScore;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int win1 = 0;
            int win2 = 0;
            for (int i = 0; i < 500; i++)
            {
                int team1Score = GenScore();
                int team2Score = GenScore();

                if (team1Score > team2Score)
                    win1++;
                else
                    win2++;

                MessageBox.Show("India: " + team1Score + "\n" + "Aus: " + team2Score);
            }

            
            MessageBox.Show("India: " + win1 + "\n" + "Aus: " + win2);
        }

        RandomGen o = new RandomGen();

        private int GenScore()
        {            
            int iTotal = 0;
            String s = "";
            int[] oArr = new int[7] { 0, 0, 0, 0, 0, 0, 0 };

            for (int i = 0; i < 300; i++)
            {
                int iCurrent = 0;
                iCurrent = o.Generate();
                oArr[iCurrent]++;
                iTotal = iTotal + iCurrent;
                s = s + "\n" + iCurrent.ToString();
            }

            //MessageBox.Show(iTotal.ToString());
            string sss = "";
            for (int i = 0; i < oArr.Length; i++)
            {
                sss = sss + i.ToString() + " " + oArr[i].ToString() + "\n";
            }
            //MessageBox.Show(sss);
            return iTotal;
        }
    }
}
